#include"logger.h"
logger *logger:: _pInstance=nullptr;
Category *logger:: _root=&log4cpp::Category::getRoot();

logger*logger:: getInstance(){
    if(_pInstance==nullptr){
        _pInstance=new logger();
    }
    return _pInstance;
}
void logger:: destory(){
    if(_pInstance!=nullptr){
        Category::shutdown();
        delete _pInstance;
        _pInstance=nullptr;
    }
}
logger:: logger(){

 std::string initFileName = "log4cpp.properties";
    log4cpp::PropertyConfigurator::configure(initFileName);


//    PatternLayout * ptn1 = new PatternLayout();
//    ptn1->setConversionPattern("%d %c [%p] %m%n");
//
//    PatternLayout * ptn2 = new PatternLayout();
//    ptn2->setConversionPattern("%d %c [%p] %m%n");
//
//    PatternLayout * ptn3 = new PatternLayout();
//    ptn3->setConversionPattern("%d %c [%p] %m%n");
//
//    OstreamAppender *appender1 = new OstreamAppender("console", &std::cout);
//    appender1->setLayout(ptn1);
//
//    FileAppender *appender2 = new FileAppender("default", "aliyun.log");
//    appender2->setLayout(ptn2);
//
//    RollingFileAppender  *appender3 = new RollingFileAppender("rollinfile", "aliyunrolling.log",5*1024,9);
//    appender3->setLayout(ptn3);
//
//    _root->setPriority(log4cpp::Priority::DEBUG);
//    _root->addAppender(appender1);
//    _root->addAppender(appender2);
//    _root->addAppender(appender3);
}
logger::~ logger(){
    cout<<"~logger()"<<endl;

}
void logger::debug(const char * file, int line, const char * func, const string msg)
{
    _root->debug("%s %d %s %s",file,line,func,msg.c_str()); 
}
void logger::info(const char * file, int line, const char * func, const string msg)
{
    _root->info("%s %d %s %s",file,line,func,msg.c_str()); 
}
void logger::warn(const char * file, int line, const char * func, const string msg)
{
    _root->warn("%s %d %s %s",file,line,func,msg.c_str()); 

}
void logger::error(const char * file, int line, const char * func, const string msg)
{
    _root->error("%s %d %s %s",file,line,func,msg.c_str()); 

}





